package com.zy.explore.license.interfaces.facade.example;

import com.zy.explore.license.interfaces.frm.CommonIdFrm;
import com.zy.explore.license.interfaces.frm.CommonIdsFrm;
import com.zy.explore.license.interfaces.vo.PageVO;
import com.zy.explore.license.interfaces.assembler.MpExampleAssembler;
import com.zy.explore.license.interfaces.frm.ExampleSaveFrm;
import com.zy.explore.license.interfaces.frm.ExampleQueryFrm;
import com.zy.explore.license.interfaces.vo.ExampleVO;
import com.zy.explore.license.infrastructure.constant.Router;
import com.zy.explore.license.infrastructure.constant.ExampleRouter;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * description mybatis-plus示例Facade
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2022年04月17日 01:33:12
 */
@Api(tags = "mybatis-plus示例Facade")
@RestController
@RequestMapping(ExampleRouter.MP_EXAMPLE_ROUTER)
public class MpExampleFacade {


    /**
     * 注入assembler
     */
    @Resource
    private MpExampleAssembler assembler;

    /**
     * 新增数据
     *
     * @param frm 待新增的Frm对象
     * @return 成功返回新增后的VO对象，失败返回null
     */
    @ApiOperationSupport(order = 10, author = "🇨🇳中国印🇨🇳", ignoreParameters = {"id"})
    @ApiOperation("①新增数据")
    @PostMapping(Router.INSERT)
    public ExampleVO insert(@RequestBody @Validated ExampleSaveFrm frm) {
        return assembler.insert(frm);
    }

    /**
     * 删除数据
     *
     * @param frm 主键Frm对象
     * @return 1:删除成功 其他:删除失败
     */
    @ApiOperationSupport(order = 20, author = "🇨🇳中国印🇨🇳")
    @ApiOperation("②删除数据")
    @PostMapping(Router.DELETE)
    public Integer delete(@RequestBody @Validated CommonIdFrm frm) {
        return assembler.delete(frm);
    }

    /**
     * 更新数据
     *
     * @param frm 待更新的Frm对象
     * @return 成功返回更新后的VO对象，失败返回null
     */
    @ApiOperationSupport(order = 30, author = "🇨🇳中国印🇨🇳")
    @ApiOperation("③更新数据")
    @PostMapping(Router.UPDATE)
    public ExampleVO update(@RequestBody @Validated ExampleSaveFrm frm) {
        return assembler.update(frm);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param frm 主键Frm对象
     * @return 成功返回对应ID的VO对象，查询不到返回null
     */
    @ApiOperationSupport(order = 40, author = "🇨🇳中国印🇨🇳")
    @ApiOperation("④根据主键查询数据")
    @PostMapping(Router.FIND_BY_ID)
    public ExampleVO findById(@RequestBody @Validated CommonIdFrm frm) {
        return assembler.findById(frm);
    }

    /**
     * 通过主键集合查询多条数据
     *
     * @param frm 主键集合Frm对象
     * @return 成功返回对应ID的VO对象，若查询不到则返回空集合，非null
     */
     @ApiOperationSupport(order = 50, author = "🇨🇳中国印🇨🇳")
     @ApiOperation("⑤根据主键集批量查询数据")
     @PostMapping(Router.FIND_BY_IDS)
     public List<ExampleVO> findByIds(@RequestBody @Validated CommonIdsFrm frm) {
        return assembler.findByIds(frm);
     }

    /**
     * 根据条件获取数据集
     *
     * @param frm 查询条件对象
     * @return 满足条件的数据集合，若查询不到则返回空集合，非null
     */
    @ApiOperationSupport(order = 60, author = "🇨🇳中国印🇨🇳", ignoreParameters = {"pageNum", "pageSize"})
    @ApiOperation("⑥根据条件查询数据集")
    @PostMapping(Router.FIND_LIST)
    public List<ExampleVO> findList(@RequestBody @Validated ExampleQueryFrm frm) {
        return assembler.findList(frm);
    }

    /**
     * 根据条件查询数据分页
     *
     * @param frm 查询条件参数
     * @return 成功返回满足条件的分页，若查询不到，则返回内部数组为空集合，非null
     */
    @ApiOperationSupport(order = 70, author = "🇨🇳中国印🇨🇳")
    @ApiOperation("⑦根据条件查询数据分页")
    @PostMapping(Router.FIND_PAGE)
    public PageVO<ExampleVO> findPage(@RequestBody @Validated ExampleQueryFrm frm) {
        return assembler.findPage(frm);
    }

}
